package org.example.huweb.web.sys_test.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.Result.Result;
import org.example.Result.ResultUtils;
import org.example.huweb.web.sys_login.controller.userController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class test {
    //手动创建日志
    private static final Logger log = LoggerFactory.getLogger(userController.class);

    //测试接口
    @RequestMapping("/longinTxt")
    public Result txt(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        log.info("test接口被调用");
        //实例获取HttpServletRequest中的所以信息
        System.out.println("————————请求头参数————————");
        Enumeration<String> headerNames = req.getHeaderNames();
        headerNames.asIterator().forEachRemaining(e -> {
            System.out.println(e + ":" + req.getHeader(e));
        });

        System.out.println("————————请求路径参数————————");
        String pathInfo = req.getPathInfo();
        System.out.println(pathInfo);

        System.out.println("————————请求参数————————");
        Map<String, String[]> trailerFields = req.getParameterMap();
        trailerFields.forEach((k, v) -> {
            System.out.println(k + ":" + Arrays.toString(v));
        });

        System.out.println("————————Body:参数————————");
        String body = req.getReader().lines().reduce("", String::concat);
        System.out.println(body);

        //返回结果 时间戳
        return  ResultUtils.success(System.currentTimeMillis());
    }
}
